package com.lagou.demo.controller;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.StandardCharsets;

@RestController
public class MessageController {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @RequestMapping("/rabbit/{message}")
    public String receive(@PathVariable String message){
        MessageProperties properties = MessagePropertiesBuilder.newInstance().setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN).setContentEncoding("utf-8").build();
        Message msg = MessageBuilder.withBody(message.getBytes(StandardCharsets.UTF_8)).andProperties(properties).build();
        amqpTemplate.send("ex.boot","key.boot",msg);
        return "success";
    }


}
